package com.cn.longdistancebusstation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cn.longdistancebusstation.R;
import com.cn.longdistancebusstation.model.BusInfo;
import com.cn.longdistancebusstation.model.TicketInfo;
import com.cn.longdistancebusstation.view.MotorCoachNumberListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mucheng on 2018/1/29.
 */

public class MotorCoachNumberAdapter extends BaseAdapter{
    private Context ctx;
    private List<BusInfo> ticket;
    public MotorCoachNumberAdapter(Context ctx,List<BusInfo> ticket){
        this.ctx=ctx;
        this.ticket=ticket;
    }
    @Override
    public int getCount() {
        return ticket.size();
    }

    @Override
    public Object getItem(int i) {
        return ticket.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if(view==null){
            holder=new ViewHolder();
            view= LayoutInflater.from(ctx).inflate(R.layout.view_motorcoachnumber,null);
            holder.tv_bus_type_or_time=(TextView)view.findViewById(R.id.bus_type_or_time);
            holder.tv_bus_standards=(TextView)view.findViewById(R.id.standards);
            holder.tv_station_origin=(TextView)view.findViewById(R.id.station_origin);
            holder.tv_station_arrive=(TextView)view.findViewById(R.id.station_arrive);
            holder.tv_bus_motorCoachNumber=(TextView)view.findViewById(R.id.bus_motorCoachNumber);
            holder.tv_ticket_price=(TextView)view.findViewById(R.id.bus_motorCoachNumber);
            holder.tv_ticket_has_or_no=(TextView)view.findViewById(R.id.ticket_has_or_no);
            view.setTag(holder);
        }else{
            holder=(ViewHolder)view.getTag();
        }
        BusInfo motorCoachNumber=ticket.get(i);
        Boolean isFlow=motorCoachNumber.getFlow();
        if(isFlow){
            holder.tv_bus_type_or_time.setText("流水车");
        }else{
            holder.tv_bus_type_or_time.setText(motorCoachNumber.getSendTime());
        }
        holder.tv_bus_motorCoachNumber.setText(motorCoachNumber.getBusNo());
        holder.tv_station_origin.setText(motorCoachNumber.getStartStationName());
        holder.tv_station_arrive.setText(motorCoachNumber.getEndStationName());
        holder.tv_ticket_price.setText(motorCoachNumber.getTicketPrice());
//        holder.tv_ticket_has_or_no.setText(motorCoachNumber.getTicketStatus());

        return view;
    }
    class ViewHolder{
        TextView tv_bus_type_or_time;
        TextView tv_bus_standards;
        TextView tv_station_origin;
        TextView tv_station_arrive;
        TextView tv_bus_motorCoachNumber;
        TextView tv_ticket_price;
        TextView tv_ticket_has_or_no;

    }
}
